package com.wn.equipment.web;

import com.wn.common.PageBean;
import com.wn.common.ResponseEntity;
import com.wn.entity.*;
import com.wn.equipment.openfeign.ActivitiFeignClient;
import com.wn.equipment.service.EquipmentManagementService;
import com.wn.equipment.service.FeedBackService;
import com.wn.equipment.service.PersonalDetailsService;
import com.wn.equipment.vo.EquipmentVo;
import com.wn.equipment.vo.FeedbackVo;
import com.wn.equipment.vo.HrVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author zhairenhao
 * @date 2022/10/20 15:37
 */
@RequestMapping("/equipment")
@RestController
public class EquipmentController {
    @Autowired
    EquipmentManagementService equipmentManagementService;

    @Autowired
    private ActivitiFeignClient activitiFeignClient;

    @Autowired
    private PersonalDetailsService personalDetailsService;

    @Autowired
    FeedBackService feedBackService;

    @RequestMapping("/addition2")
    public ResponseEntity addition(@RequestBody FeedbackVo feedbackVo) {

        PageBean<Feedback> pageBean = feedBackService.getEquipmentByPages(feedbackVo);

        return new ResponseEntity(pageBean);
    }

    @RequestMapping("/select")
    @ResponseBody
    public ResponseEntity select(EquipmentManagement equipmentManagement){
        List<EquipmentManagement> lists = equipmentManagementService.getAll();

//        ResponseEntity responseEntity = activitiFeignClient.startInstance();//调用流程微服务
        return new ResponseEntity(lists);
    }

    @RequestMapping("/addition")
    public ResponseEntity addition(@RequestBody EquipmentVo equipmentVo) {

        PageBean<EquipmentManagement> pageBean = equipmentManagementService.getEquipmentByPages(equipmentVo);

        return new ResponseEntity(pageBean);
    }

    @RequestMapping("/addition3")
    public ResponseEntity addition3(@RequestBody HrVo hrVo) {

        PageBean<Hr> pageBean = personalDetailsService.getEquipmentByPages(hrVo);

        return new ResponseEntity(pageBean);
    }

    @RequestMapping("/add1")
    public ResponseEntity add(@RequestBody Feedback feedback){
        feedBackService.insert(feedback);
        return ResponseEntity.success;
    }

    @RequestMapping("/add2")
    public ResponseEntity add2(@RequestBody EquipmentManagement equipmentManagement){
        equipmentManagementService.insert(equipmentManagement);
        return ResponseEntity.success;
    }

    @RequestMapping("/get1")
    public ResponseEntity get(int id){
        Feedback byId = feedBackService.getById(id);
        return new ResponseEntity(byId);
    }

    @RequestMapping("/get2")
    public ResponseEntity get2(int id){
        EquipmentManagement byId = equipmentManagementService.getById(id);
        return new ResponseEntity(byId);
    }

    @RequestMapping("/update1")
    public ResponseEntity update1(@RequestBody Feedback feedback){
        feedBackService.update(feedback);
        return ResponseEntity.success;
    }

    @RequestMapping("/update2")
    public ResponseEntity update2(@RequestBody EquipmentManagement equipmentManagement){
        equipmentManagementService.update(equipmentManagement);
        return ResponseEntity.success;
    }

    @RequestMapping("/del1")
    public ResponseEntity det(int id){
        equipmentManagementService.delete(id);
        return ResponseEntity.success;
    }
}
